// Upgrade NOTE: commented out 'float4x4 _Object2World', a built-in variable
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'


Shader  "Custom/HeightFogCheap" {

	Properties
	 {
 _MainTex ("Texture 1", 2D) = "white" {}
 _FogTex ("Fog Texture", 2D) = "white" {}
 _FogColour ("fog colour", Color) = (1,1,1,1)
 _Tim ("Time", Float) = 0
 _Density ("Fog Density", Float) = 0.1
 _Plane ("_Plane", Vector) = (0,1,0,1)
}

	

	SubShader
     {
  Tags { "RenderType"="Opaque" }

    LOD 100
	Pass
	{
	
	

	CGPROGRAM
	#pragma vertex vert
	#pragma fragment frag
	#include "UnityCG.cginc"
    //#define Fixed3(value)  fixed3(value, value,value)

	struct VertexInput {
    fixed4 vertex : POSITION;
	fixed2 xlv_TEXCOORD0 : TEXCOORD0;
    //fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    //fixed3 xlv_TEXCOORD2 : TEXCOORD2;
    //fixed3 xlv_TEXCOORD3 : TEXCOORD3;
    //fixed4 tangent : TANGENT;
    fixed3 normal : NORMAL;
    //fixed4 xlv_COLOR : COLOR;
	//VertexInput
	};


	struct VertexOutput {
	fixed4 pos : SV_POSITION;
    UNITY_FOG_COORDS(1)
    //fixed4 xlv_COLOR : COLOR;
	fixed2 xlv_TEXCOORD0 : TEXCOORD0;
    fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    fixed3 xlv_TEXCOORD2 : TEXCOORD2;
    //fixed3 xlv_TEXCOORD3 : TEXCOORD3;
    //fixed3 xlv_TEXCOORD4 : TEXCOORD4;
	//VertexOutput
	};

	

 
 
 
 
 // float4x4 _Object2World;
 float4 _MainTex_ST;
 float _Density;
 float4 _Plane;


	

 sampler2D _MainTex;
 sampler2D _FogTex;
 fixed4 _FogColour;




	VertexOutput vert (VertexInput v)
	{
	VertexOutput o;
	//o.pos = UnityObjectToClipPos (v.vertex);
	//o.xlv_TEXCOORD0 = TRANSFORM_TEX(v.xlv_TEXCOORD0, _MainTex);
	
  float4 tmpvar_1;
  tmpvar_1.yzw = fixed3(0.0, 0.0, 0.0);
  tmpvar_1.x = (sin((
    (_Time * 25.0)
   + 
    (v.vertex.x * 10.0)
  )) * 0.1).x;
  float4 tmpvar_2;
  tmpvar_2 = mul(unity_ObjectToWorld , v.vertex);
  float2 tmpvar_3;
  tmpvar_3.x = (_Time.x * 1.1);
  tmpvar_3.y = (_Time.x * 0.1);
  o.pos = UnityObjectToClipPos( (v.vertex + tmpvar_1));
  o.xlv_TEXCOORD0 = ((v.xlv_TEXCOORD0 * _MainTex_ST.xy) + _MainTex_ST.zw);
  o.xlv_TEXCOORD1 = ((tmpvar_2.xz / 40.0) + tmpvar_3);
  o.xlv_TEXCOORD2 = ((dot (tmpvar_2.xyz, _Plane.xyz) - _Plane.w) * _Density);

    UNITY_TRANSFER_FOG(o,o.vertex);
   
	return o;
	}


	fixed4 frag(VertexOutput i) : SV_Target
    {
    //fixed4 tmpvar_2 = tex2D(_MainTex, i.uv);
	
  half4 main_color_1;
  half fogAmount_2;
  float tmpvar_3;
  tmpvar_3 = clamp (i.xlv_TEXCOORD2, 0.0, 1.0);
  fogAmount_2 = tmpvar_3;
  fixed4 tmpvar_4;
  tmpvar_4 = tex2D (_FogTex, i.xlv_TEXCOORD1);
  half tmpvar_5;
  tmpvar_5 = clamp ((fogAmount_2 * tmpvar_4.x), 0.0, 1.0);
  fogAmount_2 = tmpvar_5;
  main_color_1.w = 0.0;
  fixed3 tmpvar_6;
  tmpvar_6 = tex2D (_MainTex, i.xlv_TEXCOORD0).xyz;
	UNITY_APPLY_FOG(i.fogCoord, tmpvar_6);
  main_color_1.xyz = tmpvar_6;
  main_color_1.xyz = lerp (main_color_1.xyz, _FogColour.xyz, fixed3(tmpvar_5,tmpvar_5,tmpvar_5));
  main_color_1.w = 1.0;
  return main_color_1;

	}
	ENDCG
	}
  }
Fallback "Diffuse"
}

